﻿// 数据中心-首页
LApp.controller('DBCenter_HomeCtrl', function ($scope, $location, $interval, $templateRequest, $timeout, $lvl, DBCenterService) {
    var _thisYear = new Date().getFullYear();
    angular.extend($scope, {
        //Statistic: {
        //    CustomerTotalCount: '-----',
        //    CarTotalCount: '-----',
        //    SaleTotalCount: '-----',
        //    RepairTotalCount: '-----'
        //},
        //GetStatistic: function () {
        //    DBCenterService.GetTotalStatictisCount({
        //        param: {},
        //        success: function (data) {
        //            $scope.IntervalStatistic(data.CustomerCount, data.CarCount, data.SaleCount, data.RepairCount);
        //        }
        //    })
        //},
        //IntervalStatistic: function (_count1, _count2, _count3, _count4) {
        //    var _count = 50;
        //    var _index = 0;
        //    var _intervalId = $interval(function () {

        //        if (_index == _count) {
        //            angular.extend($scope.Statistic, {
        //                CustomerTotalCount: _count1,
        //                CarTotalCount: _count2,
        //                SaleTotalCount: _count3,
        //                RepairTotalCount: _count4
        //            });
        //            $interval.cancel(_intervalId);
        //            return;
        //        }

        //        angular.extend($scope.Statistic, {
        //            CustomerTotalCount: Math.floor(_count1 / _count) * _index,
        //            CarTotalCount: Math.floor(_count2 / _count) * _index,
        //            SaleTotalCount: Math.floor(_count3 / _count) * _index,
        //            RepairTotalCount: Math.floor(_count4 / _count) * _index
        //        });

        //        _index++;

        //    }, 1);
        //},
        //GetYearStatisticData: function () {
        //    DBCenterService.GetBusinessStatictisCount({
        //        data: {
        //            businessType: 'Sale',
        //            year: _thisYear,
        //            month: 0
        //        },
        //        success: function (data) {
        //            $scope.InitCharts('chartA', '汽车销售', _thisYear, 0, data);
        //        }
        //    })

        //    DBCenterService.GetBusinessStatictisCount({
        //        data: {
        //            businessType: 'Repair',
        //            year: _thisYear,
        //            month: 0
        //        },
        //        success: function (data) {
        //            $scope.InitCharts('chartB', '汽车维修', _thisYear, 0, data);
        //        }
        //    })
        //},
        //InitCharts: function (_id, _title, _year, _month, s_data) {
        //    var chartA = echarts.init(document.getElementById(_id));
        //    var chartsData = CreateData(s_data);
        //    var OptionA = {
        //        title: {
        //            text: chartsData.title
        //        },
        //        toolbox: {
        //            show: true,
        //            feature: {
        //                mark: { show: true },
        //                dataView: { show: true, readOnly: true },
        //                magicType: { show: true, type: ['line', 'bar'] },
        //                saveAsImage: { show: true }
        //            }
        //        },
        //        tooltip: {
        //            trigger: 'axis',
        //            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
        //                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        //            }
        //        },
        //        legend: {
        //            data: chartsData.legend
        //        },
        //        grid: {
        //            left: '2%',
        //            right: '4%',
        //            bottom: '10%',
        //            containLabel: true
        //        },
        //        xAxis: [
        //            {
        //                type: 'category',
        //                data: chartsData.xAxis,
        //                axisLabel: {
        //                    interval: 0,
        //                    margin: 2,
        //                    textStyle: {
        //                        fontWeight: "bold",
        //                        color: "#000000"
        //                    }
        //                }
        //            }
        //        ],
        //        yAxis: [
        //            {
        //                type: 'value'
        //            }
        //        ],
        //        series: chartsData.series

        //    };
        //    chartA.setOption(OptionA);


        //    function CreateData(data) {
        //        var result = {};
        //        if (_month == 0) {
        //            result.title = _year + "全年" + _title + "业务";
        //        } else {
        //            result.title = _year + "年" + _month + "月份" + _title + "业务";
        //        }

        //        result.xAxis = [];

        //        for (var i = 0; i < data.xAxis.length; i++) {
        //            result.xAxis.push(data.xAxis[i] + ((_month == 0) ? '月' : '日'));
        //        }

        //        result.legend = data.legend;

        //        result.series = [];
        //        for (var i = 0; i < result.legend.length; i++) {
        //            var item = {
        //                name: result.legend[i],
        //                type: 'bar',
        //                normal: {
        //                    color: 'rgb(119,169,174)'
        //                },
        //                data: data.datas[i]
        //            };
        //            result.series.push(item);
        //        }
        //        return result;
        //    }
        //}
    })
    //$scope.GetStatistic();
    //$scope.GetYearStatisticData();
});


LApp.controller('DBCenter_CommnetListCtrl', function ($scope, $location, $interval, $templateRequest, $timeout, $lvl, DBCenterService) {
    //扩展
    angular.extend($scope, {
        ConditionModel: {
            pageIndex: 1,
            pageSize: 20,
            searchKey: null
        },
        //加载
        GetCommentReplyPageList: function (pageIndex) {
            $scope.ConditionModel.pageIndex = pageIndex || 1;
            DBCenterService.GetCommentReplyPagedList({
                data: $scope.ConditionModel,
                success: function (response) {
                    $scope.CommentReplyList = response;
                }
            })
        },
        DeleteCommentReply: function (item) {
            DBCenterService.DeleteCommentReply({
                data: { Id: item.ID },
                success: function (response) {
                    $scope.GetCommentReplyPageList($scope.ConditionModel.pageIndex);
                    $lvl.msgSuccess("完成");
                }
            })
        },
        Dialog_AddCommentReply: function () {
            $scope.OpType = "Add";
            $scope.CommentReplyModel = {};
            $lvl.dialog({
                scope: $scope,
                title: "添加",
                template:CONTENT_URL('Pages/DBCenter/AntiFake/Dialog_AddOrEditComment.html')
            })
        },
        Dialog_EditCommentReply: function (item) {
            $scope.OpType = "Edit";
            $scope.CommentReplyModel =angular.copy(item);
            $lvl.dialog({
                scope: $scope,
                title: "编辑",
                template: CONTENT_URL('Pages/DBCenter/AntiFake/Dialog_AddOrEditComment.html')
            })
        },
        SaveCommentReply: function (_$close) {
            if (_$close) { _$close(); }
            if ($scope.OpType == "Add") {
                DBCenterService.AdddCommentReply({
                    data: $scope.CommentReplyModel,
                    success: function (response) {
                        $lvl.msgSuccess("OK");
                        $scope.GetCommentReplyPageList();
                    }
                })
            } else {
                DBCenterService.EditCommentReply({
                    data: $scope.CommentReplyModel,
                    success: function (response) {
                        $lvl.msgSuccess("OK");
                        $scope.GetCommentReplyPageList($scope.ConditionModel.pageIndex);
                    }
                })
            }
        }
    })
    $scope.GetCommentReplyPageList();
})

//片区管理
LApp.controller('DBCenter_AreaManagerListCtrl', function ($scope, $location, $interval, $templateRequest, $timeout, $lvl, DBCenterService) {
    angular.extend($scope, {
        ConditionModel: {
            pageIndex: 1,
            pageSize: 20,
            searchKey:null
        },
        GetSaleAreaList: function (pageindex) {
            $scope.ConditionModel.pageIndex = pageindex || 1;
            DBCenterService.GetSalesAreaList({
                data: $scope.ConditionModel,
                success: function (response) {
                    $scope.SalesAreaList = response;
                }
            })
        },
        Dialog_AddSalesArea: function () {
            $scope.OpType = "Add";
            $scope.SalesAreaModel = {};
            $lvl.dialog({
                scope: $scope,
                title: "添加",
                template: CONTENT_URL('Pages/DBCenter/Manager/Dialog_AddOrEditSaleArea.html')
            })
        },
        Dialog_EditSalesArea: function (item) {
            $scope.OpType = "Edit";
            $scope.SalesAreaModel = angular.copy(item);
            $lvl.dialog({
                scope: $scope,
                title: "编辑",
                template: CONTENT_URL('Pages/DBCenter/Manager/Dialog_AddOrEditSaleArea.html')
            })
        },
        SaveSaleArea: function (_$close) {
            if ($scope.OpType == "Add") {
                DBCenterService.AddSalesArea({
                    data: $scope.SalesAreaModel,
                    success: function (ressponse) {
                        $scope.GetSaleAreaList();
                        $lvl.msgSuccess("OK");
                        if (_$close) { _$close(); }
                    }
                })
            } else {
                DBCenterService.EditSalesArea({
                    data: $scope.SalesAreaModel,
                    success: function (ressponse) {
                        $scope.GetSaleAreaList($scope.ConditionModel.pageIndex);
                        $lvl.msgSuccess("OK");
                        if (_$close) { _$close(); }
                    }
                })
            }
        }
        ,


        DeleteSalesArea: function (item) {
            $lvl.msgConfirm("are you ok", function () {
                DBCenterService.DeleteSalesArea({
                    data: { Id: item.ID },
                    success: function (ressponse) {
                        $scope.GetSaleAreaList();
                        $lvl.msgSuccess("OK");
                    }
                })
            });

        
           
        }
    })
    $scope.GetSaleAreaList();
})